package com.xtoad.ecms.baseinfo.model;

import com.xtoad.ecms.baseinfo.enums.Sex;
import com.xtoad.ecms.common.web.base.BaseModel;
import org.hibernate.annotations.Table;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;
import java.util.List;

/**
 * 用户实体类
 *
 * @author xtoad
 * @date 2020/05/29
 */
@Entity
@Table(appliesTo = "user", comment = "用户表")
public class User extends BaseModel {

    private static final long serialVersionUID = -1616905035103332302L;
    /**
     * 姓名
     */
    @Column(nullable = true, columnDefinition = "varchar(100) comment '姓名'")
    private String name;

    /**
     * 登录名
     */
    @Column(nullable = false, unique = true, columnDefinition = "varchar(50) comment '登录名'")
    private String loginNo;

    /**
     * 昵称
     */
    @Column(nullable = true, columnDefinition = "varchar(100) comment '昵称'")
    private String nickName;

    /**
     * 邮箱
     */
    @Column(nullable = false, columnDefinition = "varchar(50) comment '邮箱'")
    private String email;

    /**
     * 手机
     */
    @Column(nullable = false, columnDefinition = "varchar(14) comment '手机'")
    private String phone;

    /**
     * 生日
     */
    @Temporal(TemporalType.DATE)
    @Column(nullable = true, columnDefinition = "date comment '生日'")
    private Date birthday;

    /**
     * 性别
     */
    @Column(nullable = false, columnDefinition = "varchar(10) comment '性别'")
    @Enumerated(EnumType.STRING)
    private Sex sex;

    /**
     * 密码
     */
    @Column(nullable = false, columnDefinition = "varchar(70) comment '密码'")
    private String password;

    /**
     * 角色列表
     */
    @ManyToMany(fetch = FetchType.LAZY)
    private List<Role> roles;

    /**
     * 构造方法
     *
     * @param name     姓名
     * @param nickName 昵称
     * @param email    邮箱
     * @param phone    手机
     * @param birthday 生日
     * @param sex      性别
     * @param password 密码
     */
    public User(String name, String loginNo, String nickName, String email
            , String phone, Date birthday, Sex sex
            , String password) {
        this.name = name;
        this.loginNo = loginNo;
        this.nickName = nickName;
        this.email = email;
        this.phone = phone;
        this.birthday = birthday;
        this.sex = sex;
        this.password = password;
    }

    /**
     * 默认构造函数
     */
    public User() {
    }


    /**
     * 获取 姓名
     */
    public String getName() {
        return this.name;
    }

    /**
     * 设置 姓名
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取 登录名
     */
    public String getLoginNo() {
        return this.loginNo;
    }

    /**
     * 设置 登录名
     */
    public void setLoginNo(String loginNo) {
        this.loginNo = loginNo;
    }

    /**
     * 获取 昵称
     */
    public String getNickName() {
        return this.nickName;
    }

    /**
     * 设置 昵称
     */
    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    /**
     * 获取 邮箱
     */
    public String getEmail() {
        return this.email;
    }

    /**
     * 设置 邮箱
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * 获取 手机
     */
    public String getPhone() {
        return this.phone;
    }

    /**
     * 设置 手机
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * 获取 生日
     */
    public Date getBirthday() {
        return this.birthday;
    }

    /**
     * 设置 生日
     */
    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    /**
     * 获取 性别
     */
    public Sex getSex() {
        return this.sex;
    }

    /**
     * 设置 性别
     */
    public void setSex(Sex sex) {
        this.sex = sex;
    }

    /**
     * 获取 密码
     */
    public String getPassword() {
        return this.password;
    }

    /**
     * 设置 密码
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * 获取 角色列表
     */
    public List<Role> getRoles() {
        return this.roles;
    }

    /**
     * 设置 角色列表
     */
    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", loginNo='" + loginNo + '\'' +
                ", nickName='" + nickName + '\'' +
                ", email='" + email + '\'' +
                ", phone='" + phone + '\'' +
                ", birthday=" + birthday +
                ", sex=" + sex +
                ", password='" + password + '\'' +
                ", roles=" + roles +
                "} " + super.toString();
    }
}
